<?php
$row = $data_member->row();
?>
<script type="text/javascript">
    var array = [];
    $(document).ready(function() {
        function validate_input(attname, attinput, atterror) {
            if (!attname) {
                $(attinput).attr('class', "inp-form-error");
                $(atterror).attr('style', 'visibility:visible');
                array.push(false);
            } else {
                $(attinput).attr('class', "inp-form");
                $(atterror).attr('style', 'visibility:hidden');
                array.push(true);
            }
        }

        function validate_textarea(attname, attinput, atterror) {
            if (!attname) {
                $(attinput).attr('class', "form-textarea-error");
                $(atterror).attr('style', 'visibility:visible');
                array.push(false);
            } else {
                $(attinput).attr('class', "form-textarea");
                $(atterror).attr('style', 'visibility:hidden');
                array.push(true);
            }
        }

        function validate_dropdown(attname, atterror) {
            if (attname <= 0) {
                $(atterror).attr('style', 'visibility:visible');
                array.push(false);
            } else {
                $(atterror).attr('style', 'visibility:visible');
                array.push(true);
            }
        }

        function validate_pass(attname1, attname2, attinput1, attinput2, atterror1, atterror2) {

            if (attname1 && attname2) {
                if (attname1 != attname2) {
                    $(atterror1).attr('style', 'visibility:visible');
                    $(atterror2).attr('style', 'visibility:visible');
                    document.getElementById("sub_error_pass").innerHTML = 'Password is not same with Confirm Password.';
                    document.getElementById("sub_error_conPwd").innerHTML = ' Confirm Password is not same with Password.';
                    array.push(false);
                } else {
                    $(atterror1).attr('style', 'visibility:hidden');
                    $(atterror2).attr('style', 'visibility:hidden');
                    array.push(true);
                }
            } else {
                validate_input(attname1, attinput1, atterror1);
                validate_input(attname2, attinput2, atterror2);
            }
        }

        function validate_email(attemail, attinput, atterror) {
            var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (attemail) {
                if (regex.test(attemail)) {
                    $(attinput).attr('class', "inp-form");
                    $(atterror).attr('style', 'visibility:hidden');
                    array.push(true);
                } else {
                    $(attinput).attr('class', "inp-form-error");
                    $(atterror).attr('style', 'visibility:visible');
                    document.getElementById("sub_error_email").innerHTML = 'Email format is not valid.';
                    array.push(false);
                }
            } else {
                $(attinput).attr('class', "inp-form-error");
                $(atterror).attr('style', 'visibility:visible');
                document.getElementById("sub_error_email").innerHTML = 'This field is required.';
                array.push(false);
            }
        }

        //validate form
        $("input[name='submit']").click(function() {
            var user = $("input[name='signup_username']").val();
            var pass = $("input[name='signup_password']").val();
            var conpass = $("input[name='signup_confirmPwd']").val();
            var idcard = $("input[name='signup_idCard']").val();
            var first = $("input[name='signup_firstname']").val();
            var last = $("input[name='signup_lastname']").val();
            var address = $("textarea[name='signup_address']").val();
            var tele = $("input[name='signup_mobile']").val();
            var email = $("input[name='signup_email']").val();

            array.length = 0;
            validate_input(user, "input[name='signup_username']", "div[id='error_username']");
//            validate_pass(pass, conpass, "input[name='signup_password']", "input[name='signup_confirmPwd']", "div[id='error_password']", "div[id='error_confirmPassword']");
            validate_input(idcard, "input[name='signup_idCard']", "div[id='error_idCard']");
            validate_input(first, "input[name='signup_firstname']", "div[id='error_firstname']");
            validate_input(last, "input[name='signup_lastname']", "div[id='error_lastname']");
            validate_textarea(address, "textarea[name='signup_address']", "div[id='error_address']");
            validate_input(tele, "input[name='signup_mobile']", "div[id='error_mobile']");
            validate_email(email, "input[name='signup_email']", "div[id='error_email']");

            for (var i in array) {
                if (!array[i]) {
                    return false;
                    break;
                }
            }
            alert('Editing is complete.');
        });

        $("button[name='reset']").click(function() {
            $("input[name='signup_username']").val('<?php echo $row->USERNAME; ?>');
            $("input[name='signup_idCard']").val('<?php echo $row->ID_CARD; ?>');
            $("input[name='signup_firstname']").val('<?php echo $row->FIRSTNAME; ?>');
            $("input[name='signup_lastname']").val('<?php echo $row->LASTNAME; ?>');
//            $("select[name='signup_day']").select(0);
//            $("select[name='signup_month']").select(0);
//            $("select[name='signup_year']").select(0);
            $("textarea[name='signup_address']").val('<?php echo $row->ADDRESS; ?>');
            $("input[name='signup_mobile']").val('<?php echo $row->MOBILE; ?>');
            $("input[name='signup_email']").val('<?php echo $row->EMAIL; ?>');
        });

        // keypress event only numer
        $("input[name='signup_idCard']").bind('keypress', function(e) {
            return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) ? false : true;
        });
        $("input[name='signup_mobile']").bind('keypress', function(e) {
            return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) ? false : true;
        });

    });
</script>

<div id="content-outer">
    <div id="content">
        <div id="page-heading"><h1>Edit Member</h1></div>
        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
            <tbody>
                <tr>
                    <th rowspan="3" class="sized"><img src="<?php echo base_url(); ?>images/shared/side_shadowleft.jpg" width="20" height="300" alt=""></th>
                    <th class="topleft"></th>
                    <td id="tbl-border-top">&nbsp;</td>
                    <th class="topright"></th>
                    <th rowspan="3" class="sized"><img src="<?php echo base_url(); ?>images/shared/side_shadowright.jpg" width="20" height="300" alt=""></th>
                </tr>
                <tr>
                    <td id="tbl-border-left"></td>
                    <td>
                        <!--  start content-table-inner -->
                        <div id="content-table-inner">

                            <table border="0" width="100%" cellpadding="0" cellspacing="0">

                                <tbody><tr valign="top">
                                        <td>


                                            <!-- start id-form -->
                                            <table border="0" cellpadding="0" cellspacing="0" id="id-form">
                                                <?php
                                                echo form_open('EditMember/UpdateProfile');
                                                ?>
                                                <tbody><tr>
                                                        <th valign="top">Username:</th>
                                                        <td>
                                                            <?php
                                                                echo form_input($username, $row->USERNAME, $member['username'] . 'class="inp-form"');
                                                            ?> 
                                                        </td>
                                                        <td style="width:500px">
                                                            <div width="400px" id="error_username" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">ID Card Number:</th>
                                                        <td>
                                                            <?php
                                                                echo form_input($idCard, $row->ID_CARD, $member['idCard'] . 'class="inp-form" maxlength="13"');
                                                            ?> 
                                                        </td>
                                                        <td>
                                                            <div id="error_idCard" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div>
                                                        </td>
                                                    </tr> 
                                                    <tr>
                                                        <th valign="top">First Name:</th>
                                                        <td><?php
                                                                echo form_input($firstname, $row->FIRSTNAME, $member['firstname'] . 'class="inp-form"');
                                                            ?></td>
                                                        <td><div id="error_firstname" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div></td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">Last Name:</th>
                                                        <td>
                                                            <?php
                                                                echo form_input($lastname, $row->LASTNAME, $member['lastname'] . 'class="inp-form"');
                                                            ?>
                                                        </td>
                                                        <td><div id="error_lastname" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div></td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">BirthDay:</th>
                                                        <td class="noheight">

                                                            <table border="0" cellpadding="0" cellspacing="0">
                                                                <tbody>
                                                                    <tr valign="top">
                                                                            <td><?php echo form_dropdown('signup_day', $days, intval(date('d', strtotime($row->DOB))), $member['day'] . $day) ?></td>
                                                                            <td><?php echo form_dropdown('signup_month', $months, intval(date('m', strtotime($row->DOB))), $member['month'] . $month) ?></td>
                                                                            <td><?php echo form_dropdown('signup_year', $years, date('Y', strtotime($row->DOB)), $member['year'] . $year) ?></td>
                                                                            <?php if ($member['username'] != ""): ?>
                                                                                <td><a href="" id="date-pick" class="dp-applied" style="display:none;"><img src="<?php echo base_url(); ?>images/forms/icon_calendar.jpg" alt=""></a></td>
                                                                            <?php else: ?>
                                                                                <td><a href="" id="date-pick" class="dp-applied" ><img src="<?php echo base_url(); ?>images/forms/icon_calendar.jpg" alt=""></a></td>
                                                                            <?php endif; ?>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </td>
                                                        <td></td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">Address:</th>
                                                        <td><?php
                                                                echo form_textarea($address, $row->ADDRESS, $member['address'] . 'class="form-textarea"');
                                                            ?></td>
                                                        <td>
                                                            <div id="error_address" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">Mobile No.:</th>
                                                        <td><?php
                                                                echo form_input($mobile, $row->MOBILE, $member['mobile'] . 'class="inp-form" maxlength="10"');
                                                            ?></td>
                                                        <td>
                                                            <div id="error_mobile" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner">This field is required.</div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th valign="top">Email:</th>
                                                        <td><?php
                                                                echo form_input($email, $row->EMAIL, $member['email'] . 'class="inp-form"');
                                                            ?></td>
                                                        <td>
                                                            <div id="error_email" style="visibility:hidden">
                                                                <div class="error-left"></div>
                                                                <div class="error-inner" id="sub_error_email">This field is required.</div>
                                                            </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th>&nbsp;</th>
                                                            <td valign="top">
                                                                <?php echo form_submit('submit', 'Submit', 'class="form-submit"'); ?>
                                                                <?php echo form_button('reset', 'Reset', 'class="form-reset"'); ?>
                                                            </td>
                                                        <td></td>
                                                    </tr>
                                                </tbody>
                                                <?php echo form_close(); ?>
                                            </table>
                                            <!-- end id-form  -->
                                            
                                        </td>
                                        <td>



                                        </td>
                                    </tr>
                                    <tr>
                                        <td><img src="images/shared/blank.gif" width="695" height="1" alt="blank"></td>
                                        <td></td>
                                    </tr>
                                </tbody></table>


                            <div class="clear"></div>


                        </div>
                        <!--  end content-table-inner  -->
                    </td>
                    <td id="tbl-border-right"></td>
                </tr>
                <tr>
                    <th class="sized bottomleft"></th>
                    <td id="tbl-border-bottom">&nbsp;</td>
                    <th class="sized bottomright"></th>
                </tr>
            </tbody></table>

        <div class="clear">&nbsp;</div>
    </div>
</div>